﻿using System.Collections.Generic;
using System.Linq;
using System.Windows.Controls;
using System.Xml.Linq;

namespace ComicTool.Drawing.Svg
{
    public class TextArea
    {
        private readonly List<TextLine> textLines = new List<TextLine>();

        public TextArea(XElement element)
        {
            var textInfo = new TextInfo();
            //string space = (string)nav.Evaluate("string(ancestor::*[@xml:space][1]/@xml:space)", new XmlNamespaceManager(nav.NameTable));
            //if (space != "")
            //    textInfo.preserveWS = space == "preserve";
            textInfo.LoadInfo(element.Attributes().ToList());

            foreach (XElement x in element.Elements().Where(x => x.Name == "text"))
            {
                textLines.Add(new TextLine(textInfo.Clone(), x));
            }
        }

        public IEnumerable<TextBlock> CreateBlocks()
        {
            return textLines.Select(t => t.Draw());
        }
    }



}